﻿<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>教务管理系统 - 请假管理</title>
    <link href="${pageContext.request.contextPath}/resources/bootstrap5/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons - 本地版本 -->
    <link href="${pageContext.request.contextPath}/resources/bootstrap-icons/1.11.3/bootstrap-icons.css" rel="stylesheet">
    <!-- Bootstrap Icons - 备用CDN -->
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
    <!-- 第二个备用CDN -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
    <style>
        body {
            font-family: "Microsoft YaHei", sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
        }

        .header {
            background-color: #1976d2;
            color: white;
            padding: 10px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            position: fixed;
            width: 100%;
            top: 0;
            z-index: 1000;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .header h2 {
            margin: 0;
            font-size: 1.5rem;
            display: flex;
            align-items: center;
        }

        .header h2 img {
            height: 36px;
            margin-right: 10px;
        }

        .header .breadcrumb {
            margin: 0;
            background: transparent;
            color: white;
        }

        .header .breadcrumb a {
            color: rgba(255,255,255,0.8);
            text-decoration: none;
        }

        .header .breadcrumb a:hover {
            color: white;
        }

        .header .breadcrumb-item.active {
            color: white;
        }

        .header .breadcrumb-item+.breadcrumb-item::before {
            color: rgba(255,255,255,0.6);
        }

        /* 侧边栏样式 */
        .sidebar {
            position: fixed;
            top: 56px;
            left: 0;
            bottom: 0;
            width: 250px;
            background-color: white;
            box-shadow: 2px 0 5px rgba(0,0,0,0.1);
            overflow-y: auto;
            z-index: 100;
            padding-top: 20px;
        }

        .sidebar-menu {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .sidebar-menu > li {
            margin-bottom: 5px;
        }

        .sidebar-menu > li > a {
            display: flex;
            align-items: center;
            padding: 12px 20px;
            color: #333;
            text-decoration: none;
            transition: all 0.3s;
            border-left: 3px solid transparent;
        }

        .sidebar-menu > li > a:hover {
            background-color: #f0f0f0;
            border-left-color: #1976d2;
        }

        .sidebar-menu > li > a.active {
            background-color: #e3f2fd;
            border-left-color: #1976d2;
            color: #1976d2;
        }

        .sidebar-menu > li > a i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 1.1rem;
        }

        .sidebar-submenu {
            list-style: none;
            padding-left: 53px;
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease;
        }

        .sidebar-menu > li.open .sidebar-submenu {
            max-height: 500px;
        }

        .sidebar-submenu > li > a {
            display: block;
            padding: 8px 0;
            color: #666;
            text-decoration: none;
            transition: all 0.3s;
        }

        .sidebar-submenu > li > a:hover {
            color: #1976d2;
        }

        .sidebar-submenu > li > a.active {
            color: #1976d2;
            font-weight: 500;
        }

        /* 内容区样式 */
        .content {
            margin-left: 250px;
            padding: 76px 20px 20px;
        }

        /* 用户名下拉菜单样式 */
        .header-user {
            display: flex;
            align-items: center;
            position: relative;
            cursor: pointer;
            padding: 8px 12px;
            border-radius: 8px;
            transition: all 0.2s ease;
        }
        .header-user:hover {
            background-color: rgba(255,255,255,0.1);
        }
        .header-user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            margin-right: 8px;
            object-fit: cover;
            background: #fff;
            cursor: pointer;
            transition: transform 0.2s;
            border: 2px solid rgba(255,255,255,0.3);
        }
        .header-user-avatar:hover {
            transform: scale(1.1);
        }
        .header-user-name {
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
            color: white;
        }
        .user-dropdown {
            position: absolute;
            top: 100%;
            right: 0;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            min-width: 160px;
            z-index: 1001;
            opacity: 0;
            visibility: hidden;
            transform: translateY(-10px);
            transition: all 0.3s ease;
            margin-top: 8px;
        }
        .user-dropdown.show {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }
        .user-dropdown-item {
            display: flex;
            align-items: center;
            padding: 12px 16px;
            color: #333;
            text-decoration: none;
            transition: background-color 0.2s;
            border-bottom: 1px solid #f0f0f0;
            font-size: 0.9rem;
        }
        .user-dropdown-item:last-child {
            border-bottom: none;
        }
        .user-dropdown-item:hover {
            background-color: #f8f9fa;
            color: #1976d2;
        }
        .user-dropdown-item i {
            margin-right: 8px;
            width: 16px;
            text-align: center;
        }

        /* 按钮样式 */
        .btn-apply {
            background-color: #28a745;
            border-color: #28a745;
            color: white;
            font-weight: 500;
            padding: 10px 20px;
            border-radius: 6px;
        }

        .btn-apply:hover {
            background-color: #218838;
            border-color: #1e7e34;
            color: white;
        }

        .btn-cancel {
            background-color: #dc3545;
            border-color: #dc3545;
            color: white;
            font-weight: 500;
            padding: 6px 12px;
            border-radius: 6px;
            font-size: 0.85rem;
        }

        .btn-cancel:hover {
            background-color: #c82333;
            border-color: #bd2130;
            color: white;
        }

        /* 搜索容器样式 */
        .search-container {
            background: white;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }

        /* 表格样式 */
        .leave-table {
            width: 100%;
            border-collapse: collapse;
            background: white;
            margin-bottom: 0;
        }

        .leave-table th {
            background-color: #f8f9fa;
            color: #495057;
            font-weight: 600;
            padding: 15px 12px;
            text-align: center;
            border-top: none;
            border-bottom: 2px solid #dee2e6;
            white-space: nowrap;
        }

        .leave-table td {
            padding: 12px;
            text-align: center;
            border-bottom: 1px solid #dee2e6;
            vertical-align: middle;
        }

        .leave-table tbody tr:hover {
            background-color: rgba(25,118,210,0.05);
        }

        /* 状态标签样式 */
        .status-badge {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.8rem;
            font-weight: 500;
            display: inline-block;
        }

        .status-pending {
            background-color: #fff3cd;
            color: #856404;
        }

        .status-approved {
            background-color: #d4edda;
            color: #155724;
        }

        .status-rejected {
            background-color: #f8d7da;
            color: #721c24;
        }

        /* 原因单元格样式 */
        .reason-cell {
            max-width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            text-align: left;
        }

        /* 卡片样式 */
        .card {
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            border: 1px solid #dee2e6;
            overflow: hidden;
        }

        .card-header {
            background-color: #f8f9fa;
            color: #495057;
            border-bottom: 1px solid #dee2e6;
            padding: 15px 20px;
        }

        .card-header h5 {
            margin: 0;
            font-weight: 600;
            display: flex;
            align-items: center;
        }

        .card-header h5 i {
            margin-right: 10px;
        }

        /* 空状态样式 */
        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: #6c757d;
        }

        .empty-state i {
            font-size: 4rem;
            color: #dee2e6;
            margin-bottom: 20px;
        }

        .empty-state h5 {
            color: #6c757d;
            margin-bottom: 10px;
        }

        /* 分页样式 */
        .pagination .page-link {
            color: #495057;
            border: 1px solid #dee2e6;
            margin: 0 2px;
            border-radius: 6px;
        }

        .pagination .page-item.active .page-link {
            background-color: #1976d2;
            border-color: #1976d2;
            color: white;
        }

        .pagination .page-link:hover {
            color: #1976d2;
            background-color: #f8f9fa;
            border-color: #dee2e6;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
                transition: transform 0.3s ease;
            }

            .sidebar.active {
                transform: translateX(0);
            }

            .content {
                margin-left: 0;
            }

            .leave-table {
                font-size: 0.8rem;
            }

            .leave-table th,
            .leave-table td {
                padding: 8px 5px;
            }
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<div class="header">
    <div class="header-left">
        <h2><img src="${pageContext.request.contextPath}/resources/images/logo.png" alt="Logo"> 教务管理系统</h2>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="${pageContext.request.contextPath}/student/home">首页</a></li>
                <li class="breadcrumb-item"><a href="${pageContext.request.contextPath}/student/my-courses">教学管理</a></li>
                <li class="breadcrumb-item active">请假管理</li>
            </ol>
        </nav>
    </div>

    <!-- 用户下拉菜单 -->
    <div class="header-user" id="userDropdownContainer">
        <img src="${pageContext.request.contextPath}/resources/images/baimao.png" class="header-user-avatar" alt="用户头像" id="userAvatar">
        <span class="header-user-name" id="userName">
            <c:choose>
                <c:when test="${not empty currentStudent and not empty currentStudent.user and not empty currentStudent.user.realName}">
                    ${currentStudent.user.realName}
                </c:when>
                <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.realName}">
                    ${sessionScope.loggedInUser.realName}
                </c:when>
                <c:when test="${not empty sessionScope.loggedInUser and not empty sessionScope.loggedInUser.username}">
                    ${sessionScope.loggedInUser.username}
                </c:when>
                <c:otherwise>
                    学生
                </c:otherwise>
            </c:choose>
        </span>
        <div class="user-dropdown" id="userDropdown">
            <a href="#" class="user-dropdown-item" onclick="showProfileModal()">
                <i class="bi bi-person-circle"></i>
                个人信息
            </a>
            <a href="${pageContext.request.contextPath}/student/changePassword" class="user-dropdown-item">
                <i class="bi bi-key"></i>
                修改密码
            </a>
            <a href="${pageContext.request.contextPath}/user/logout" class="user-dropdown-item">
                <i class="bi bi-box-arrow-right"></i>
                退出系统
            </a>
        </div>
    </div>
</div>

<!-- 侧边栏 -->
<%@ include file="../common/student-sidebar.jsp" %>

<!-- 主内容区 -->
<div class="content">
    <c:if test="${not empty error}">
        <div class="alert alert-danger" role="alert">
            <i class="bi bi-exclamation-triangle"></i> ${error}
        </div>
    </c:if>

    <!-- 申请请假按钮 -->
    <div class="mb-3">
        <button type="button" class="btn btn-apply" data-bs-toggle="modal" data-bs-target="#applyLeaveModal">
            <i class="bi bi-plus-circle me-1"></i> 申请请假
        </button>
    </div>

    <!-- 搜索功能 -->
    <div class="search-container">
        <form action="${pageContext.request.contextPath}/student/leave" method="get" class="row g-3">
            <div class="col-md-4">
                <label for="courseNameSearch" class="form-label">课程名称</label>
                <input type="text" class="form-control" id="courseNameSearch" name="courseNameSearch"
                       value="${courseNameSearch}" placeholder="输入课程名称进行搜索...">
            </div>
            <div class="col-md-3">
                <label for="statusSearch" class="form-label">审核状态</label>
                <select class="form-select" id="statusSearch" name="statusSearch">
                    <option value="">全部状态</option>
                    <option value="0" ${statusSearch == 0 ? 'selected' : ''}>待审核</option>
                    <option value="1" ${statusSearch == 1 ? 'selected' : ''}>审核通过</option>
                    <option value="2" ${statusSearch == 2 ? 'selected' : ''}>审核不通过</option>
                </select>
            </div>
            <div class="col-md-5 d-flex align-items-end">
                <button type="submit" class="btn btn-primary me-2">
                    <i class="bi bi-search"></i> 搜索
                </button>
                <a href="${pageContext.request.contextPath}/student/leave" class="btn btn-outline-secondary">
                    <i class="bi bi-arrow-clockwise"></i> 重置
                </a>
            </div>
        </form>
    </div>

    <!-- 请假记录列表 -->
    <div class="card">
        <div class="card-header">
            <h5><i class="bi bi-calendar-x-fill"></i> 我的请假记录</h5>
        </div>
        <div class="card-body p-0">
            <c:choose>
                <c:when test="${not empty leaves}">
                    <div class="table-responsive">
                        <table class="leave-table">
                            <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>课程名称</th>
                                    <th>请假原因</th>
                                    <th>开始时间</th>
                                    <th>结束时间</th>
                                    <th>请假天数</th>
                                    <th>审核状态</th>
                                    <th>申请时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <c:forEach items="${leaves}" var="leave" varStatus="status">
                                    <tr>
                                        <td>${(currentPage - 1) * pageSize + status.index + 1}</td>
                                        <td style="text-align: left; font-weight: 500;">
                                            <c:choose>
                                                <c:when test="${not empty leave.course and not empty leave.course.name}">
                                                    ${leave.course.name}
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="text-muted">未知课程</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td class="reason-cell" title="${leave.reason}">
                                            <c:choose>
                                                <c:when test="${not empty leave.reason}">
                                                    ${leave.reason}
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="text-muted">无原因</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${not empty leave.startTime}">
                                                    ${leave.startTime}
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="text-muted">-</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${not empty leave.endTime}">
                                                    ${leave.endTime}
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="text-muted">-</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${leave.leaveDays > 0}">
                                                    ${leave.leaveDays} 天
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="text-muted">计算中...</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${leave.status == 0}">
                                                    <span class="status-badge status-pending">待审核</span>
                                                </c:when>
                                                <c:when test="${leave.status == 1}">
                                                    <span class="status-badge status-approved">审核通过</span>
                                                </c:when>
                                                <c:when test="${leave.status == 2}">
                                                    <span class="status-badge status-rejected">审核不通过</span>
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="text-muted">未知状态</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${not empty leave.createTime}">
                                                    ${leave.createTime}
                                                </c:when>
                                                <c:otherwise>
                                                    <span class="text-muted">-</span>
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                            <c:if test="${leave.status == 0}">
                                                <c:choose>
                                                    <c:when test="${not empty leave.id}">
                                                        <button type="button" class="btn btn-cancel" onclick="cancelLeave('${leave.id}')">
                                                            <i class="bi bi-x-circle"></i> 撤销
                                                        </button>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <span class="text-muted">无法操作</span>
                                                    </c:otherwise>
                                                </c:choose>
                                            </c:if>
                                            <c:if test="${leave.status != 0}">
                                                <span class="text-muted">无法操作</span>
                                            </c:if>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </tbody>
                        </table>
                    </div>

                    <!-- 分页控件 -->
                    <div class="d-flex justify-content-between align-items-center p-3">
                        <div class="text-muted">
                            共 ${totalRecords} 条记录，第 ${currentPage} / ${totalPages} 页
                        </div>
                        <nav aria-label="请假分页">
                            <ul class="pagination mb-0">
                                <c:if test="${currentPage > 1}">
                                    <li class="page-item">
                                        <a class="page-link" href="?page=1&size=${pageSize}&courseNameSearch=${courseNameSearch}&statusSearch=${statusSearch}">首页</a>
                                    </li>
                                    <li class="page-item">
                                        <a class="page-link" href="?page=${currentPage - 1}&size=${pageSize}&courseNameSearch=${courseNameSearch}&statusSearch=${statusSearch}">上一页</a>
                                    </li>
                                </c:if>

                                <c:forEach begin="${currentPage - 2 > 1 ? currentPage - 2 : 1}"
                                          end="${currentPage + 2 < totalPages ? currentPage + 2 : totalPages}"
                                          var="pageNum">
                                    <li class="page-item ${pageNum == currentPage ? 'active' : ''}">
                                        <a class="page-link" href="?page=${pageNum}&size=${pageSize}&courseNameSearch=${courseNameSearch}&statusSearch=${statusSearch}">${pageNum}</a>
                                    </li>
                                </c:forEach>

                                <c:if test="${currentPage < totalPages}">
                                    <li class="page-item">
                                        <a class="page-link" href="?page=${currentPage + 1}&size=${pageSize}&courseNameSearch=${courseNameSearch}&statusSearch=${statusSearch}">下一页</a>
                                    </li>
                                    <li class="page-item">
                                        <a class="page-link" href="?page=${totalPages}&size=${pageSize}&courseNameSearch=${courseNameSearch}&statusSearch=${statusSearch}">末页</a>
                                    </li>
                                </c:if>
                            </ul>
                        </nav>
                    </div>
                </c:when>
                <c:otherwise>
                    <div class="empty-state">
                        <i class="bi bi-calendar-x"></i>
                        <h5>暂无请假记录</h5>
                        <p class="text-muted">
                            <c:choose>
                                <c:when test="${not empty courseNameSearch or not empty statusSearch}">
                                    没有找到符合条件的请假记录
                                </c:when>
                                <c:otherwise>
                                    您还没有提交过请假申请<br>
                                    点击上方"申请请假"按钮可以提交新的请假申请
                                </c:otherwise>
                            </c:choose>
                        </p>
                    </div>
                </c:otherwise>
            </c:choose>
        </div>
    </div>
</div>

<!-- 申请请假模态框 -->
<div class="modal fade" id="applyLeaveModal" tabindex="-1" aria-labelledby="applyLeaveModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header" style="background-color: #28a745; color: white; border-bottom: 1px solid #dee2e6;">
                <h5 class="modal-title" id="applyLeaveModalLabel">
                    <i class="bi bi-calendar-plus"></i> 申请请假
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <form id="applyLeaveForm">
                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <label for="courseId" class="form-label">选择课程 <span class="text-danger">*</span></label>
                            <select class="form-select" id="courseId" name="courseId" required>
                                <option value="">请选择课程</option>
                                <c:forEach items="${availableCourses}" var="course">
                                    <option value="${course.id}">${course.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="col-md-3 mb-3">
                            <label for="startTime" class="form-label">开始时间 <span class="text-danger">*</span></label>
                            <input type="date" class="form-control" id="startTime" name="startTime" required>
                        </div>
                        <div class="col-md-3 mb-3">
                            <label for="endTime" class="form-label">结束时间 <span class="text-danger">*</span></label>
                            <input type="date" class="form-control" id="endTime" name="endTime" required>
                        </div>
                    </div>
                    <div class="mb-3">
                        <label for="reason" class="form-label">请假原因 <span class="text-danger">*</span></label>
                        <textarea class="form-control" id="reason" name="reason" rows="4"
                                  placeholder="请详细说明请假原因..." maxlength="500" required></textarea>
                        <div class="form-text">最多500字</div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-apply">
                        <i class="bi bi-check-circle me-1"></i>提交申请
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- 个人信息模态框 -->
<div class="modal fade" id="profileModal" tabindex="-1" aria-labelledby="profileModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content" style="border-radius: 8px;">
            <div class="modal-header" style="background-color: #1976d2; color: white; border-bottom: 1px solid #dee2e6;">
                <h5 class="modal-title" id="profileModalLabel">
                    <i class="bi bi-person-circle"></i> 个人信息
                </h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="padding: 30px;">
                <c:if test="${not empty currentStudent}">
                    <div class="row mb-4">
                        <div class="col-12 text-center">
                            <div style="width: 80px; height: 80px; border-radius: 50%; margin: 0 auto 15px; background-color: #1976d2; display: flex; align-items: center; justify-content: center; color: white; font-size: 2rem;">
                                <i class="bi bi-person-circle"></i>
                            </div>
                            <h5 class="mb-1">
                                <c:choose>
                                    <c:when test="${not empty currentStudent.user.realName}">
                                        ${currentStudent.user.realName}
                                    </c:when>
                                    <c:otherwise>
                                        学生信息
                                    </c:otherwise>
                                </c:choose>
                            </h5>
                            <p class="text-muted mb-0">学生个人信息详情</p>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-person me-2"></i>姓名</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.user.realName}">
                                            ${currentStudent.user.realName}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-card-text me-2"></i>学号</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.studentNo}">
                                            ${currentStudent.studentNo}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-person-badge me-2"></i>用户名</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.user.username}">
                                            ${currentStudent.user.username}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-gender-ambiguous me-2"></i>性别</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${currentStudent.gender == 1}">
                                            <span class="badge" style="background: #e3f2fd; color: #1976d2;">男</span>
                                        </c:when>
                                        <c:when test="${currentStudent.gender == 0}">
                                            <span class="badge" style="background: #fce4ec; color: #e91e63;">女</span>
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-building me-2"></i>班级</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.name}">
                                            ${currentStudent.clazz.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未分配班级</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-mortarboard me-2"></i>专业</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.major and not empty currentStudent.clazz.major.name}">
                                            ${currentStudent.clazz.major.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未分配专业</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-bank me-2"></i>学院</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.clazz and not empty currentStudent.clazz.major and not empty currentStudent.clazz.major.college and not empty currentStudent.clazz.major.college.name}">
                                            ${currentStudent.clazz.major.college.name}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未分配学院</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-envelope me-2"></i>电子邮箱</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.email}">
                                            ${currentStudent.email}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 mb-3">
                            <div style="padding: 15px; background: #f8f9fa; border-radius: 8px; border-left: 4px solid #1976d2;">
                                <strong style="color: #1976d2;"><i class="bi bi-telephone me-2"></i>联系电话</strong>
                                <div class="mt-1">
                                    <c:choose>
                                        <c:when test="${not empty currentStudent.phone}">
                                            ${currentStudent.phone}
                                        </c:when>
                                        <c:otherwise>
                                            <span class="text-muted">未设置</span>
                                        </c:otherwise>
                                    </c:choose>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:if>

                <c:if test="${empty currentStudent}">
                    <div class="text-center py-5">
                        <i class="bi bi-exclamation-circle text-warning" style="font-size: 3rem;"></i>
                        <h5 class="mt-3">无法获取学生信息</h5>
                        <p class="text-muted">请联系管理员或重新登录</p>
                    </div>
                </c:if>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                <a href="${pageContext.request.contextPath}/student/changePassword" class="btn btn-primary">
                    <i class="bi bi-key me-1"></i>修改密码
                </a>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/resources/bootstrap5/js/bootstrap.bundle.min.js"></script>
<script>
    // 用户下拉菜单
    document.getElementById('userDropdownContainer').addEventListener('click', function(e) {
        e.stopPropagation();
        console.log('用户头像区域被点击了 - 请假页面');
        const dropdown = document.getElementById('userDropdown');
        
        if (!dropdown) {
            console.error('找不到下拉菜单元素');
            return;
        }
        
        // 使用更准确的状态检测
        const computedStyle = window.getComputedStyle(dropdown);
        const isReallyVisible = computedStyle.opacity !== '0' && computedStyle.visibility !== 'hidden' && dropdown.offsetHeight > 0;
        
        console.log('CSS opacity:', computedStyle.opacity);
        console.log('CSS visibility:', computedStyle.visibility);
        console.log('元素高度:', dropdown.offsetHeight);
        console.log('真实显示状态:', isReallyVisible);
        
        if (isReallyVisible) {
            // 隐藏
            dropdown.style.opacity = '0';
            dropdown.style.visibility = 'hidden';
            dropdown.style.transform = 'translateY(-10px)';
            dropdown.classList.remove('show');
            console.log('隐藏下拉菜单');
        } else {
            // 显示
            dropdown.style.opacity = '1';
            dropdown.style.visibility = 'visible';
            dropdown.style.transform = 'translateY(0)';
            dropdown.classList.add('show');
            console.log('显示下拉菜单');
        }
    });

    // 点击其他地方关闭下拉菜单
    document.addEventListener('click', function() {
        const dropdown = document.getElementById('userDropdown');
        if (dropdown) {
            dropdown.style.opacity = '0';
            dropdown.style.visibility = 'hidden';
            dropdown.style.transform = 'translateY(-10px)';
            dropdown.classList.remove('show');
        }
    });

    // 侧边栏子菜单切换
    function toggleSubmenu(element) {
        const parent = element.parentElement;
        const submenu = parent.querySelector('.sidebar-submenu');

        // 关闭其他打开的子菜单
        document.querySelectorAll('.sidebar-menu > li').forEach(li => {
            if (li !== parent) {
                li.classList.remove('open');
            }
        });

        // 切换当前子菜单
        parent.classList.toggle('open');
    }

    // 申请请假表单提交
    document.getElementById('applyLeaveForm').addEventListener('submit', function(e) {
        e.preventDefault();

        // 获取表单数据
        const courseId = document.getElementById('courseId').value;
        const startTime = document.getElementById('startTime').value;
        const endTime = document.getElementById('endTime').value;
        const reason = document.getElementById('reason').value;

        // 验证必填字段
        if (!courseId) {
            alert('请选择课程');
            return;
        }

        if (!startTime) {
            alert('请选择开始时间');
            return;
        }

        if (!endTime) {
            alert('请选择结束时间');
            return;
        }

        if (!reason.trim()) {
            alert('请填写请假原因');
            return;
        }

        // 验证日期
        const startDate = new Date(startTime);
        const endDate = new Date(endTime);
        const today = new Date();
        today.setHours(0, 0, 0, 0);

        if (startDate < today) {
            alert('开始时间不能早于今天');
            return;
        }

        if (endDate < startDate) {
            alert('结束时间不能早于开始时间');
            return;
        }

        // 使用URL编码方式提交数据
        const params = new URLSearchParams();
        params.append('courseId', courseId);
        params.append('startTime', startTime);
        params.append('endTime', endTime);
        params.append('reason', reason.trim());

        fetch('${pageContext.request.contextPath}/student/leave/apply', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'X-Requested-With': 'XMLHttpRequest'
            },
            body: params
        })
        .then(response => {
            if (!response.ok) {
                throw new Error('网络请求失败');
            }
            return response.json();
        })
        .then(data => {
            if (data.success) {
                alert('请假申请提交成功！');
                const modal = bootstrap.Modal.getInstance(document.getElementById('applyLeaveModal'));
                modal.hide();
                // 清空表单
                document.getElementById('applyLeaveForm').reset();
                location.reload();
            } else {
                alert('申请失败：' + data.message);
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('申请失败，请稍后重试');
        });
    });

    // 撤销请假申请
    function cancelLeave(leaveId) {
        if (confirm('确定要撤销这个请假申请吗？撤销后无法恢复！')) {
            // 使用URL编码方式提交数据
            const params = new URLSearchParams();
            params.append('leaveId', leaveId);

            fetch('${pageContext.request.contextPath}/student/leave/cancel', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'X-Requested-With': 'XMLHttpRequest'
                },
                body: params
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error('网络请求失败');
                }
                return response.json();
            })
            .then(data => {
                if (data.success) {
                    alert('请假申请撤销成功！');
                    location.reload();
                } else {
                    alert('撤销失败：' + data.message);
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('撤销失败，请稍后重试');
            });
        }
    }

    // 页面加载完成后的初始化
    document.addEventListener('DOMContentLoaded', function() {
        // 自动展开包含当前页面的菜单
        const currentPath = window.location.pathname;
        const menuItems = document.querySelectorAll('.sidebar-submenu a');

        menuItems.forEach(item => {
            if (currentPath.includes(item.getAttribute('href'))) {
                item.classList.add('active');
                const parentLi = item.closest('.sidebar-menu > li');
                if (parentLi) {
                    parentLi.classList.add('open');
                }
            }
        });

        // 设置日期输入框的默认值
        const today = new Date().toISOString().split('T')[0];
        document.getElementById('startTime').setAttribute('min', today);
        document.getElementById('endTime').setAttribute('min', today);

        // 开始时间变化时，更新结束时间的最小值
        document.getElementById('startTime').addEventListener('change', function() {
            document.getElementById('endTime').setAttribute('min', this.value);
        });
    });

    // 显示个人信息模态框
    function showProfileModal() {
        // 关闭用户下拉菜单
        const dropdown = document.getElementById('userDropdown');
        dropdown.style.display = 'none';
        dropdown.classList.remove('show');

        // 显示模态框
        const modal = new bootstrap.Modal(document.getElementById('profileModal'));
        modal.show();
    }
</script>
</body>
</html> 

